<?php
/**
 * Progress bar
 * @author Tomas Srna
 * @package bakalarka
 */

class ProgressbarWriter implements Writer
{
	private $value;
	private $total;
	
	private $writer = NULL;
	
	public function __construct($value, $total = 100, $writer = NULL)
	{
		$this->value = $value;
		$this->total = $total;
		$this->writer = $writer;
	}
	
	public function setValue($value)
	{
		$this->value = $value;
	}
	
	public function __toString()
	{
		$t = "";
		$t .= "<span class=\"progressbar\">
<span class=\"progress\" style=\"width: ";
		$t .= round(($this->value/$this->total)*100); 
		$t .= "%\"></span>";
		$t .= "</span>
<span class=\"progressvalue\">";
		if($this->writer)
			$t.=$this->writer->set($this->value);
		else
			$t.= $this->value;
		$t.= ' ';
		$t.= L::selected()->of;
		$t.= ' ';
		if($this->writer)
			$t.= $this->writer->set($this->total);
		else
			$t.= $this->total;
		$t .= "</span>";
		
		return $t;
	}
	
	public function write()
	{
		echo (string)$this;
	}
}
